package com.dy.nygl.controller;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dy.nygl.pojo.Region;
import com.dy.nygl.service.RegionService;

@Controller
@RequestMapping("/region")
public class RegionController {

	@Resource(name="regionService")
	private RegionService regionService;
	
	@RequestMapping("/getRegion.action")
	@ResponseBody    //由于要向页面返回数据，所以必须加注解
	public List<Map<String, Object>> getRegion(HttpServletResponse response) {		
		
		List<Region> regionList = regionService.getRegion();
		
		if(regionList != null) {
			List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
			for(int i=0; i<regionList.size(); i++) {
				Map<String, Object> map = new LinkedHashMap <String, Object>();
				map.put("id",regionList.get(i).getId());
				map.put("name", regionList.get(i).getName());
				list.add(map);					
			}	
			return list;
		}
		return null;
	}

}
